package com.crl.ssc.dic.service;

import com.cars.util.global.GlobalOperaCode;
import com.cars.util.list.ListUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.crl.ssc.dic.dao.DicInfoDao;
import com.crl.ssc.dic.dto.DicInfoDTO;
import com.crl.ssc.dic.model.DicInfo;
import com.crl.ssc.dic.vo.DicInfoSearchVO;
import java.util.List;

/**
 * @description: 基础信息-企业企业Service
 * @author: MqSql
 * @version: 1.0
 * @date: 2020-08-06 18:16:54
 */
@Service
public class DicInfoService {
    @Autowired
    private DicInfoDao dicInfoDao;
    /**
     * 增加
     *
     * @param dicInfoDTO
     * @return
     */
    public int add(DicInfoDTO dicInfoDTO) {
        DicInfo dicInfo = new DicInfo();
        BeanUtils.copyProperties(dicInfoDTO, dicInfo);
        return dicInfoDao.add(dicInfo);
    }
    /**
     * 修改
     *
     * @param dicInfoDTO
     * @return
     */
    public int update(DicInfoDTO dicInfoDTO) {
        DicInfo dicInfo = new DicInfo();
        BeanUtils.copyProperties(dicInfoDTO, dicInfo);
        return dicInfoDao.update(dicInfo);
    }
    /**
     * 删除
     *
     * @param id
     * @return
     */
    public int delete(Integer id) {
        DicInfo dicInfo = dicInfoDao.get(id);
        if (dicInfo  == null) {
           return GlobalOperaCode.OPERA_NOT_EXIST;
         } else {
           return dicInfoDao.delete(id);
         }
    }

    /**
     * 列表
     *
     * @param dicInfoSearchVO
     * @return
     */
    public List<DicInfoDTO> list(DicInfoSearchVO dicInfoSearchVO) {
        List<DicInfo> list = dicInfoDao.list(dicInfoSearchVO);
        List<DicInfoDTO> listResult = ListUtils.copyList(list, DicInfoDTO.class);
        return listResult;
    }
    /**
     * 记录条数
     *
     * @param dicInfoSearchVO
     * @return
     */
    public int count(DicInfoSearchVO dicInfoSearchVO) {
        return dicInfoDao.count(dicInfoSearchVO);
    }
    /**
     * 获取单个
     *
     * @param id
     * @return
     */
    public DicInfoDTO get(Integer id) {
        DicInfo dicInfo = dicInfoDao.get(id);
        DicInfoDTO dicInfoDTO = new DicInfoDTO();
        BeanUtils.copyProperties(dicInfo, dicInfoDTO);
        return dicInfoDTO;
    }
}
